-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add: skip-subtrees option #89
base: master
Are you sure you want to change the base?
Conversation
Hi Akira, It looks like you've done a very thorough job here, and it should provide the feature you need. But I think the design is too specific to the feature, and I don't think we should add extra, feature-specific arguments and options if we can do it in a more flexible way. Thinking about this idea again, I think a simpler solution might be something like this: (org-ql-select files
'(todo)
:action '(prog1
(org-element-headline-parser (line-end-position))
(org-end-of-subtree))) Looking at the loop in (cond (preamble (let ((case-fold-search preamble-case-fold))
(cl-loop while (re-search-forward preamble nil t)
do (outline-back-to-heading 'invisible-ok)
when (funcall predicate)
collect (funcall action)
do (outline-next-heading))))
(t (cl-loop when (funcall predicate)
collect (funcall action)
while (outline-next-heading)))) The call to All that would remain would be to, possibly, wrap the pattern to make it easier to apply for the user, maybe something like: (org-ql-select files
'(todo)
:action '(ql element skip-subtree)) Which would mean, roughly: "The action is an org-ql special action form (which implies developing an "action" vocabulary and documenting it, of course, but that opens up a number of possibilities in a flexible way). First, return the element (same as the Some other ideas for the action forms: (org-ql-select files
'(todo)
;; Intending to emphasize that `skip-subtree' is not what's returned.
:action '(ql element :then skip-subtree)) (org-ql-select files
'(todo)
;; Using existing Lisp forms.
:action '(ql (prog1 element (skip-subtree))) Or, for this case at least, maybe we wouldn't need a special action form, but just a few special functions like (org-ql-select files
'(todo)
;; Using existing Lisp forms.
:action '(prog1 element (skip-subtree)) What do you think? Thanks for your work on this. Regardless of the code that we finally use, you've helped move us toward the final solution. |
Thank you for your comment.
Thanks to
You are right. We want to keep the API as minimal as possible while extending its functionality. (org-ql-select files
'(todo)
:action '(prog1
(org-element-headline-parser (line-end-position))
(org-end-of-subtree))) I haven't thought of this idea, and it would work for My question is, though, how about agenda views, i.e. |
That's a good point. I think we can add support for the Line 222 in fb830f8
:action nil if none is specified. And if we add keyword argument support to org-ql-block as discussed, I think that will handle that as well. What do you think?
|
That will be good. Please feel free to close this PR and work on the feature. Back to the original discussion, I don't mind whichever style you choose. I now prefer the following form due to its balance between conciseness and explicitness: :action '(prog1 element (skip-subtree)) I personally even don't need the I also thought of |
Thanks. I'll plan to work on this after tagging 0.4, and I'll leave this open for now since it has useful discussion about the plans. |
492ed77
to
c4f9a58
Compare
1359cbb
to
b3601cf
Compare
af2582f
to
8baeeea
Compare
I just had another idea about how to set the subtree-skipping option: an optional property list at the beginning of a query. Something like: (org-ql-select files
'(and :skip-subtrees t (todo))
:action 'element) I don't love that idea, but it is somewhat idiomatic Elisp, e.g. like |
That syntax looks strange at first but an excellent idea at the same time. It's probably the best way to support the feature discussed in this thread, especially in that it would allow dynamically enabling the feature in Still, |
Yeah, it does seem strange and familiar at the same time. Maybe we should try to get more opinions on the syntax. :) |
e441d88
to
4194456
Compare
f52bef0
to
ec0f8c7
Compare
Looking at that idea again, I really don't like it, because it would mean that queries would no longer be predicate sexps. Maybe a wrapper form could be used, something like |
Or maybe
Because of what it actually does, it may be better to allow the preprocessor in the action. |
That makes sense. The feature probably don't deserve the added complexity, so I am welcome to the rejection. |
To be clear, what I meant that I don't like is this syntax I suggested: (org-ql-select files
'(and :skip-subtrees t (todo))
:action 'element) I'm still interested in a way to skip subtrees in queries.
Yeah, I think this needs some more thought and design. Thanks. :) |
ae83de1
to
890c247
Compare
Yes, I know what you mean. Thanks to your hard work, |
That's an interesting idea. Thanks. |
Rather than extending Because those interfaces don't accept the action argument, the user cannot implement subtree skipping right now, unless he/she writes a complex query like I think it is safer to add an argument to dynamic blocks than to extend the query language or |
Akira Komamura ***@***.***> writes:
Rather than making `org-ql-select` or the query language support this feature, how about supporting this feature in `org-ql-search` and dynamic blocks for now?
An alternative to modifying :action function may be special custom
predicate. Something like
(org-ql-defpred skip-subtrees (query)
"Run QUERY skipping the whole subtree when it fails."
:preambles
((`(,predicate-names ,query)
(let ((query-preamble (org-ql--query-preamble query)))
(list :regexp (plist-get query-preamble :regexp)
:case-fold (plist-get query-preamble :case-fold)
:query `(or ,query
(progn
(org-end-of-subtree t)
nil)))))))
Then, you can
#+BEGIN: org-ql :query (skip-subtrees (todo))
#+END:
|
@yantar92 I didn't look into |
Akira Komamura ***@***.***> writes:
@yantar92 I didn't look into `org-defpred` well. Your code example apparently doesn't work, but using `org-defpred` seems to be a solution. Thank you for your information.
It worked for me. Though I did not test on master.
|
@yantar92 No, it doesn't work. It doesn't produce what I expect. Instead, the following worked: (org-ql-defpred skip-subtrees (query)
"Run QUERY skipping the whole subtree when it fails."
:normalizers
((`(root ,query)
`(and ,query
(not (ancestors ,query)))))) This may be inefficient, so it would be better if there were a solution that uses |
4f5fbc4
to
d0acc8c
Compare
059b10c
to
77b4c2b
Compare
This implements an equivalent of
org-agenda-todo-list-sublevels
variable.I basically tweaked the loop in
org-ql--select
as follows and addedskip-subtrees
argument to functions and macros in this package:It seems to be working, but I am not sure if I am doing the right thing in the preamble case. How should I add test cases?